/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "client_disc_manager.h"

#include "disc_log.h"
#include "softbus_errcode.h"
#include "disc_server_proxy.h"

int32_t DiscClientInit(void)
{
    if (DiscServerProxyInit() != SOFTBUS_OK) {
        DISC_LOGE(DISC_INIT, "disc server proxy init failed");
        return SOFTBUS_DISC_SERVER_INIT_FAILED;
    }
    DISC_LOGI(DISC_INIT, "Init success as client side");
    return SOFTBUS_OK;
}

void DiscClientDeInit(void)
{
    DiscServerProxyDeInit();
    DISC_LOGI(DISC_INIT, "DeInit success");
}

int32_t RegisterServiceInner(const ServiceInfo *serviceInfo)
{
    int32_t ret = ServerIpcRegisterService(serviceInfo);
    if (ret != SOFTBUS_OK) {
        DISC_LOGE(DISC_SDK, "Server RegisterService failed, ret=%{public}d", ret);
    }
    return ret;
}

int32_t UnRegisterServiceInner(const char *serviceId)
{
    int32_t ret = ServerIpcUnRegisterService(serviceId);
    if (ret != SOFTBUS_OK) {
        DISC_LOGE(DISC_SDK, "Server UnRegisterService failed, ret=%{public}d", ret);
    }
    return ret;
}

int32_t UpdateServiceInner(const ServiceInfo *serviceInfo)
{
    int32_t ret = ServerIpcUpdateService(serviceInfo);
    if (ret != SOFTBUS_OK) {
        DISC_LOGE(DISC_SDK, "Server UpdateService failed, ret=%{public}d", ret);
    }
    return ret;
}
